package com.culturalyard.result;

import lombok.Data;

import java.io.Serializable;

/**
 * 返回结果对象
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {
    // 状态码
    private Integer code;
    // 错误信息
    private String msg;
    // 数据
    private T data;

    // 成功：无返回数据
    public static <T> Result<T> success(){
        Result<T> result = new Result<>();
        result.code = 200;
        return result;
    }

    // 成功：携带返回数据
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.code = 200;
        result.data = data;
        return result;
    }

    // 错误返回
    public static <T> Result<T> error(Integer code,String msg){
        Result<T> result = new Result<>();
        result.code = code;
        result.msg = msg;
        return result;
    }
}
